--心扉终敞
local xingfeizhongchang = fk.CreateSkill {
    name = "mcdh_xingfeizhongchang",
}

local U = require "packages/utility/utility"
local lib = require "packages/mcdh/lib"

xingfeizhongchang:addEffect('active',{
    interaction = function()
        local choices = {"#mcdh_xingfeizhongchang-1","#mcdh_xingfeizhongchang-2"}
        return UI.ComboBox {choices = choices}
    end,
    can_use = function(self, player)
        return player:usedSkillTimes(self.name, Player.HistoryPhase) < 2
    end,
    card_num = 0,
    card_filter = function(self, to_select, selected)
        return false
    end,
    target_num = 0,
    feasible = function(self,player, targets, cards)
        if self.interaction.data == "#mcdh_xingfeizhongchang-1" then
            --暗置牌大于0且没有禁止弃置
            return not table.contains(player:getTableMark("#mcdh_xingfeizhongchang-phase"),"#mcdh_xingfeizhongchang-1") and #lib.getCanPublicCards(player) > 0 and #table.filter(lib.getCanPublicCards(player),function(id) return player:prohibitDiscard(Fk:getCardById(id)) end) == 0
        elseif self.interaction.data == "#mcdh_xingfeizhongchang-2" then
            return not table.contains(player:getTableMark("#mcdh_xingfeizhongchang-phase"),"#mcdh_xingfeizhongchang-2")
        end
    end,
    on_use = function(self, room, effect)
        local player = effect.from
        local mark = player:getTableMark("#mcdh_xingfeizhongchang-phase")
        table.insertIfNeed(mark,self.interaction.data)
        room:setPlayerMark(player,"#mcdh_xingfeizhongchang-phase",mark)
        if self.interaction.data == "#mcdh_xingfeizhongchang-1" then
            room:throwCard(lib.getCanPublicCards(player), self.name, player, player)
            U.askForUseVirtualCard(room,player,"ex_nihilo",nil,self.name,"#mcdh_xingfeizhongchang-use",false)
        else
            local cards1= lib.getPublicCards(player)
            local cards2 = lib.getCanPublicCards(player)
            for _, id in ipairs(cards1) do
                local card = Fk:getCardById(id)
                room:setCardMark(card,"@@mcdh_overt_card" , 0)
            end

            for _, id in ipairs(cards2) do
                local card = Fk:getCardById(id)
                room:setCardMark(card,"@@mcdh_overt_card" , 1)
            end
        end
    end,
})

Fk:loadTranslationTable {
    ["mcdh_xingfeizhongchang"] = "心扉终敞",
    [":mcdh_xingfeizhongchang"] = "出牌阶段各限一次，你可以：1.弃置所有暗置牌,然后视为使用一张【无中生有】;2.切换所有手牌明暗置状态。",
    ["#mcdh_xingfeizhongchang-1"] = "1.弃置所有暗置牌,然后视为使用一张【无中生有】",
    ["#mcdh_xingfeizhongchang-2"] = "2.切换所有手牌明暗置状态",
    ["#mcdh_xingfeizhongchang-use"] = "心扉终敞:视为使用一张【无中生有】",
}

return xingfeizhongchang